Skip to content

GC with Image in unsupported use cases #1979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ShahzaibIbrahim
Copy link
Contributor

@ShahzaibIbrahim ShahzaibIbrahim commented Apr 2, 2025

Logging a warning for GC initialized with unsupported use cases.

  1. all dynamic images (retrieved via any of the existing providers).
  2. all images for which handles in other zoom values have already been created.

Examples

Run this examples with following VM arguments

-Dswt.autoScale=quarter
-Dswt.autoScale.updateOnRuntime=true
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class SWTGCImageExample {
	static final ImageFileNameProvider filenameProvider = zoom -> {
		String path = null;
		switch (zoom) {
		case 150:
			path = "bin/org/eclipse/swt/snippets/eclipse.png";
			break;
		case 200:
			path = "bin/org/eclipse/swt/snippets/eclipse.png";
			break;
		default:
			path = "bin/org/eclipse/swt/snippets/eclipse.png";
		}
		return path;
	};

    public static void main(String[] args) {
    	 Display display = new Display();
         Shell shell = new Shell(display);

         Image image = new Image(display, filenameProvider);
         GC gc = new GC(image);

         // Draw something on the image
         gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
         gc.drawRectangle(50, 50, 100, 100);
         gc.drawText("Hello SWT!", 60, 90);

         // Dispose GC after drawing
         gc.dispose();

         // Dispose image
         image.dispose();

         shell.dispose();
         display.dispose();
    }
}
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class SWTImageHandleExample {
    public static void main(String[] args) {
        Display display = new Display();

        // Create an image using the display
        Image image = new Image(display, 200, 200);

        // Obtain the handle from the Image using win32_getHandle
        long handle = image.win32_getHandle(image, 100);
        System.out.println("Created image handle: " + handle);

        // Initialize GC with the image
        GC gc = new GC(image);

        // Modify the image using GC
        gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
        gc.fillRectangle(50, 50, 100, 100);

        // Dispose GC and Image
        gc.dispose();
        image.dispose();

        display.dispose();
    }
}

Copy link
Contributor

github-actions bot commented Apr 2, 2025

Test Results

   539 files   -  6     539 suites   - 6   33m 47s ⏱️ + 8m 14s
 4 337 tests  - 37   4 321 ✅  - 35   15 💤  - 3  1 ❌ +1 
16 601 runs   - 37  16 463 ✅  - 35  137 💤  - 3  1 ❌ +1 

For more details on these failures, see this check.

Results for commit 0e1052e. ± Comparison against base commit dd30aff.

This pull request removes 37 tests.
AllWin32Tests org.eclipse.swt.graphics.ImageWin32Tests ‑ testImageDataForDifferentFractionalZoomsShouldBeDifferent
AllWin32Tests org.eclipse.swt.graphics.ImageWin32Tests ‑ testImageShouldHaveDimesionAsPerZoomLevel
AllWin32Tests org.eclipse.swt.tests.win32.Test_org_eclipse_swt_dnd_DND ‑ testByteArrayTransfer
AllWin32Tests org.eclipse.swt.tests.win32.Test_org_eclipse_swt_dnd_DND ‑ testFileTransfer
AllWin32Tests org.eclipse.swt.tests.win32.Test_org_eclipse_swt_dnd_DND ‑ testHtmlTransfer
AllWin32Tests org.eclipse.swt.tests.win32.Test_org_eclipse_swt_dnd_DND ‑ testImageTransfer_fromCopiedImage
AllWin32Tests org.eclipse.swt.tests.win32.Test_org_eclipse_swt_dnd_DND ‑ testImageTransfer_fromImage
AllWin32Tests org.eclipse.swt.tests.win32.Test_org_eclipse_swt_dnd_DND ‑ testImageTransfer_fromImageData
AllWin32Tests org.eclipse.swt.tests.win32.Test_org_eclipse_swt_dnd_DND ‑ testImageTransfer_fromImageDataFromImage
AllWin32Tests org.eclipse.swt.tests.win32.Test_org_eclipse_swt_dnd_DND ‑ testRtfTransfer
…

♻️ This comment has been updated with latest results.

Copy link
Contributor

@laeubi laeubi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that printing to system out is appropriate here.

Either it is an error, then we should throw an exception or it should simply be ignored.

Logging a warning for GC initialized with unsupported use cases.
1. all dynamic images (retrieved via any of the existing providers).
2. all images for which handles in other zoom values have already been
created.
@ShahzaibIbrahim ShahzaibIbrahim marked this pull request as ready for review May 2, 2025 14:03
@ShahzaibIbrahim ShahzaibIbrahim requested a review from laeubi May 2, 2025 14:14
Copy link
Contributor

@laeubi laeubi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks now better using the error handler, but I think the message must be enhanced, e.g. it should explain what is the alternative to use instead.

Just a assume a common use-case, where I load an Image from a file, not I want to draw some test/watermark on it and save it again. How is this supposed to work? At best we add a new snippet that shows best practice on how to perform image modifications "the supported way" and then reference it in the message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Log an error, when GC with Image in unsupported use cases
4 participants